<?php
namespace Mob \ Controller;

use Think \ Controller;
use Think \ Hook;

class JobsController extends BaseController {



	public function _initialize() {
		parent :: _initialize();
		$this->_top_menu_list = array (
			'left' => array (
				array (
					'type' => 'home',
					'href' => U('Mob/Activity/activitymap'
				)
			),


		), 'center' => array (
			'title' => '知道'
		));
		if (is_login()) {


	  $this->_top_menu_list['right'][] = array (
					'type' => 'edit',
					'href' => U('Mob/Activity/creator'
				));

		} else {
			$this->_top_menu_list['right'][] = array (
				'type' => 'edit',
				'info' => '登录后才能操作！'
			);

		$this->redirect('Member/index');


		}




		$this->UserInfo = query_user(array('nickname', 'avatar64', 'uid'), $v['uid']);
		$this->setMobTitle('知道');
		$this->assign('top_menu_list', $this->_top_menu_list);

	}

	/**
	 * 主页面显示
	 */
	public function index() {

   $uid = get_uid();

   if(D('Teacher')->is_teacher($uid))
   {

    $this->redirect('Teacher/myClassGroup');
   }
   }
   //  发布招聘
   public function releasejobs()
   {
    if(IS_POST)
    {

    $title = I('post.Title',null,'string');
    $contents = I('post.contents',null,'string');
    $actlongitude = I('post.actlongitude',null,'float');
    $actlatitude = I('post.actlatitude',null,'float');
    $startDate = I('post.startDate',null,'string');
    $startDate = strtotime($startDate);
    $endDate = I('post.endDate');
    $endDate = strtotime($endDate);
    $step =  I('post.step',1,'int');
    $industryId = I('post.industry',null,'int');
    $enterpriseId = I('post.enterprise',null,'string');
    $enterpriseId = D('Enterprise')->get_NameForId($industryId,$enterpriseId);

   $jobs = D('Jobs');
   $res = $jobs->creator(null,$title,$contents,$actlongitude,$actlatitude,$startDate,$endDate,$enterpriseId,$industryId,$step);
    if($res)
    {
       $this->redirect('Jobs/jobsDetails',array('JobsId'=>$res['serialno']));

    }

     }else
     {
     $enterpriseList = D('Enterprise')->get_AllEnterprise();
     $this->assign('enterpriseList',$enterpriseList);
     $this->display();

     }

   }

   public function jobsDetails()
   {
   	$jobsId = I('JobsId');
   	 $jobs = D('Jobs');
   	$jobsDetails = $jobs->get_jobsDetails($jobsId);
   	$this->assign('jobsDetails',$jobsDetails);
   	$this->display();



   }
 ///招聘大厅
   public function jobsHall()
   {
    $jobs = D('Jobs');
    $jobsHall = $jobs->jobsHall();
    $this->assign('jobsHall',$jobsHall);
    $this->display();
   }

   //位置选择界面
   public function choosePosition()
   {

   $this->display();

   }

   public function myAttendRecord()
   {
   	$uid = get_uid();

   }
   //去地图
   public function toJobsMap()
   {
   	$jobsId = I('JobsId');
   	$jobs = D('Jobs');
    $jobsDetails = $jobs->get_jobsDetails($jobsId);
    $this->assign('jobsDetails',$jobsDetails);
    $this->display();

   }
   /// 签到操作
   public function jobsSignOperate()
   {
    if(IS_POST)
    {

    $jobId = I('post.JobsId',null,'string');
    $uid = get_uid();
    $actlongitude = I('post.actlongitude',null,'string');
    $actlatitude = I('post.actlatitude',null,'string');
    $currentStep=1;  //定义环节为1
    $jobsSign = D('JobsSign');

    $is_sign = $jobsSign->is_AlreadySign($jobId,$currentStep,$uid); //判断是否已经签到了

    if($is_sign)  //判断是否已经签到
    {
    $data = array('status'=>0,'msg'=>'已经签到，不能重复操作!');

    }else
    {

    $jobs = D('Jobs');
    $jobsDetails =$jobs->get_jobsDetails($jobId);

    $is_Distance = verifyDistance($jobsDetails['actlatitude'],$jobsDetails['actlongitude'],$actlatitude,$actlongitude,50);  //验证是否为签到地址

    if($is_Distance)
    {
    $data = array('status'=>1,'msg'=>'签到成功!');
    $signStatus=1;


    }else
    {
    $data = array('status'=>0,'msg'=>'请到正确位置进行签到操作');
    $signStatus=2;
    }

    $jobsSign = D('JobsSign');
    $jobsSign->creatorSignRecord($jobId,1,$uid,$actlongitude,$actlatitude,$signStatus,$jobsDetails['industry'],$jobsDetails['enterpriseId']);
    }
   $this->ajaxReturn($data);
    }else
    {
    $jobId = I('get.JobsId',null,'string');
    $aPage = I('page', 1, 'op_t');
    $aCount = I('count', 10, 'op_t');
    $jobs = D('Jobs');
    $uid = get_uid();
    $currentStep=1;
    $jobsDetails = $jobs->get_jobsDetails($jobId);
    $jobsSign = D('JobsSign');
    $is_sign=$jobsSign->is_AlreadySign($jobId,1,$uid);// 判断是否已经签到过了
    if($is_sign) //如果已经签到了，则可以正常显示评论信息
    {

    $where = array('businessId'=>$jobId,'status'=>1,'commentType'=>4);
  	    $comment = D('Comment')->where($where)->page($aPage, $aCount)->order('create_time desc')->select();
        $totalCount = D('Comment')->where($where)->count();
        if ($totalCount <= $aPage * $aCount) {
            $pid['count'] = 0;
        } else {
            $pid['count'] = 1;
        }
        foreach ($comment as &$k) {
        	$k['create_time']=strtotime($k['create_time']);
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['commentUid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            if($k['commentUid']==$uid||$activity['sponsorUid']==$uid)
            {
            $k['is_del']=1;
            }else
            {
            $k['is_del']=0;
            }
        }


    $this->assign('comment',$comment);
    }
    $signNum = $jobsSign->get_AlreadySignNum($jobId,$currentStep);
    $is_sign=empty($is_sign)?0:1;
    $this->assign('is_sign',$is_sign);
    $this->assign('signNum',$signNum);
    $this->assign('jobsDetails',$jobsDetails);
    $this->display();
    }
   }

   public function sendComment()
   {
   $signSerialno = I('post.signSerialno',null,'string');
   $uid = get_uid();
   $content = I('post.content',null, 'op_t');
   $to_comment_id = I('post.to_comment_id', 0, 'intval');
   $type = 4 ;//招聘评论默认为4
   $new_id =  D('Comment')->addComment($uid, $signSerialno, $content,$type, $to_comment_id);  //添加评论信息
   D('JobsSign')->update_CommentNum($signSerialno);

   $comment = D('Comment')->where(array('status' => 1, 'commentId' => $new_id))->order('create_time desc')->select();

        foreach ($comment as &$k) {
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['uid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            $k['create_time']=strtotime($k['create_time']);   //加入时间转换条件
        }

        if ($comment) {
            $data['html'] = "";
            foreach ($comment as $val) {
                $this->assign("vl", $val);
                $data['html'] .= $this->fetch("_comment");

                $data['status'] = 1;
            }
        } else {
            $data['stutus'] = 0;
        }
        $this->ajaxReturn($data);
   }


   /// 面试大厅
   public function interviewHall()
   {
   $uid = get_uid();
   $jobs = D('Jobs');
   $jobsHall = $jobs->interviewHall($uid);
   foreach($jobsHall as &$v)
   {
   $v['user']= query_user(array('nickname', 'avatar64', 'uid'), $v['signUid']);

   }
   unset($v);
   $this->assign('jobsHall',$jobsHall);
   $this->display();


   }

   public function jobsSignDetails()
   {
   	$jobsId = I('get.jobsId',null, 'op_t');
   	$signSerialno = I('get.signSerialno',null, 'op_t');
   	$jobs = D('Jobs');
   	$jobsDetails = $jobs->get_jobsDetails($jobsId);
   	$jobsSign = D('JobsSign');
    $signDetails= $jobsSign->get_SignDetails($signSerialno);
    $signDetails['user']=query_user(array('nickname', 'avatar64', 'uid'), $signDetails['signUid']);
    $comment = D('Comment')->get_CommentList($signSerialno,4);
    if($comment)
    {
     foreach ($comment as &$k) {
        	$k['create_time']=strtotime($k['create_time']);
            $k['user'] = query_user(array('nickname', 'avatar64', 'uid'), $k['commentUid']);
            $k['rand_title'] = mob_get_head_title($k['uid']);
            $k['content'] = parse_weibo_mobile_content($k['content']);
            if($k['commentUid']==$uid||$activity['sponsorUid']==$uid)
            {
            $k['is_del']=1;
            }else
            {
            $k['is_del']=0;
            }
        }


    }
    $this->assign('jobsDetails',$jobsDetails);
    $this->assign('signDetails',$signDetails);
    $this->assign('comment',$comment);
    $this->display();

   }
   //创建签到环节
   public function creatorSignStep()
   {
     if(IS_POST)
     {
     $jobsSerialno = I('post.');
     	
     	
     	
     	
     	
     	

     }else
     {
     $uid = get_uid();
     $jobsSign = D('JobsSign');
     $alreadySignRecord = $jobsSign->get_personSignRecord($uid,1); //取已经签到的招聘会
     $this->assign('alreadySignRecord',$alreadySignRecord);

     $this->display();




     }








   }
















}



